[
	$admin_toolbar += '<div id="admincontent">';
	var('this_Listerator' = (((($Listerators->find($levels->get(3)'/'))->first))->removetrailing('/')&));
	
	
	// Look for this Listerator in the Listorators table, and get heuristic settings from there
	// if there are none, no problem! the defaults will work
	var('getListeratorSettings' = 'SELECT * FROM ' $table_prefix 'Listerators WHERE Keyword_URL = "' $this_Listerator'"');
	Var: 'rewAction' = ('rewAction_Blah'); 
	inline($connection_db, -sql=$getListeratorSettings);
			if(found_count == 1);
					// we have configured heuristics
					rows;
							var(
								'these'=column('Pluralized'),
								'this'=column('Singular'),
								);
							var($rewAction + '_Table') = column('Table_name');
							var($rewAction + '_Title_Field_Name') = column('Title_Field_Name');
						
							
					/rows;
			else;
			
					var(
						'these'=($this_Listerator),
						'this'=($this_Listerator),
						);
				
					if($this_Listerator->endswith('y'));
							$these->removetrailing('y');
							$these += 'ies';
							var($rewAction + '_Table') = $these;
							var($rewAction + '_Title_Field_Name') = 'Title';
					else($this_Listerator->endswith('ies'));
							$this->removetrailing('ies');
							$this += 'y';
							var($rewAction + '_Table') = $this_Listerator;
							var($rewAction + '_Title_Field_Name') = 'Title';
					else;
							$this->removetrailing('s');
							var($rewAction + '_Table') = $this_Listerator;
							var($rewAction + '_Title_Field_Name') = 'Title';
					/if;
			/if;
	/inline;
	
	
	
	
	
	



	var(($rewAction + '_pathTo')='/Admin/'$this_Listerator'/');
	include('/_Makerator/_Library/REW_Initialization.lasso');
	// set the table for this database action 
	// build the initial fields array
	//$public_content += response_path;



			var($rewAction + '_UIDfieldName') = 'UID'; //should this be in REW?
			
			// set the table for this database action 
			var('this_table' = (var($rewAction + '_Table')));
			// build the initial fields array
			var($rewAction + '_Fields'=array);
			
			
			inline($connection_db, -table=$this_table, -sql='SHOW COLUMNS FROM '+$this_table+';');
					var($this_Listerator'_cols'= array);
					if(error_msg == 'No Error');
							iterate(column_names, var('a_column'));
									var($this_Listerator'_cols')->insert($a_column);
									//$public_content += $a_column '\r';
							/iterate;
							
							
							var('field_params' = array('Field', 'Length', 'Type', 'Default', 'Required','NULL','Table','Options'));
							var('form_fields'=array);
							var('varchar_fields' = array);
							rows;
									var('this_group'=map);
									iterate($field_params, var('a_param'));
											$this_group->insert($a_param=column($a_param));
									/iterate;
									$form_fields->insert($this_group);
							/rows;
							iterate($form_fields, var('a_group'));
									var('field' = $a_group->find('Field'));
									var('required'=(($a_group->find('NULL')) == 'YES' ? false | true));
									var('table'=var($rewAction + '_Table'));
									var('default' = $a_group->find('Default'));
									select(true);
										case(($a_group->find('Type'))->beginswith('VarChar'));
											var('type' = $a_group->find('Type'));
											$varchar_fields->insert($field);
											var('size') = ($type->split('(')->get(2)->removetrailing(')')&);
											var('type') = ($type->split('(')->get(1)->removetrailing('(')&);
											var('options' = $a_group->find('Type'));
										case(($a_group->find('Type'))->beginswith('set'));
											var('type' = $a_group->find('Type'));
											var('options' = $a_group->find('Type'));
											$options = $options->substring(5, ($options->length - 5))->split(',');
											var('size') = ($type->split('(')->get(2)->removetrailing(')')&);
											var('type') = ($type->split('(')->get(1)->removetrailing('(')&);
										case(($a_group->find('Type'))->beginswith('enum'));
											var('type' = $a_group->find('Type'));
											var('length') = ($type->split('(')->get(2)->removetrailing(')')&);
											var('options' = $a_group->find('Type'));
											$options = $options->substring(5, ($options->length - 5))->split(',');
										case(($a_group->find('Type'))->equals('date'));
											var('type' = $a_group->find('Type'));
											var('options' = $a_group->find('Type'));
											var('length'='');
											var('type') = ($type->split('(')->get(1)->removetrailing('(')&);
										case(($a_group->find('Type'))->equals('datetime'));
											var('length'='');
											var('type' = $a_group->find('Type'));
											var('type') = ($type->split('(')->get(1)->removetrailing('(')&);
											var('options' = $a_group->find('Type'));
										case(($a_group->find('Type'))->equals('text'));
											var('length'='');
											var('type' = $a_group->find('Type'));
											var('type') = ($type->split('(')->get(1)->removetrailing('(')&);
											var('options' = $a_group->find('Type'));
									/select;
									var('this_group'=map);
									iterate($field_params, var('a_param'));
											$this_group->insert($a_param=var($a_param));
									/iterate;
									(var($rewAction + '_Fields'))->insert($this_group);
									
									
									
							/iterate;
							
							include('/_Makerator/_Library/REW_finish.lasso');
							
					else;
							$page_title = 'Oops! The server made a boo&ndash;boo';
							$public_content += '<p>'error_msg'</p>';
					/if;
			/inline;


	select(true);
	case(response_path == var($rewAction + '_pathTo'));
			$page_title = $these;
			
			
			$public_content += '<div class="listerator-toolbar">
					<a class="button" href="' $REW_Base + 'Create/">Create new '$this'</a>
					<a class="button" href="/Admin/">Back to Admin</a>
					
					</div>';
			
			if(file_exists('/_Site/Listerators/'$this_Listerator'/admin-list_records.lasso'));
					//app-specific listing 
					include('/_Site/Listerators/'$this_Listerator'/admin-list_records.lasso');
			else(file_exists('/_Site/Listerators/admin-list_records.lasso'));
					// site-specific listing
					include('/_Site/Listerators/admin-list_records.lasso');
			else;
					//the default Makerator listing
					include('/_Makerator/Listerators/admin-list_records.lasso');
			/if;
			$jquery_scripts->insert('
				
				$("li.Deleted").ready(function(){
					$("li.Deleted").toggle(1000,function(){
					});
				});
				
				$("li.Hide").ready(function(){
					$("li.Hide").toggle(1000,function(){
					});
				});
				
				
				$(function(){
						$("#togglehidden").click(function(){
							$("li.Hide").toggle(1000,function(){});
						});
				});
				
				$(function(){
						$("#toggledeleted").click(function(){
							$("li.Deleted").toggle(1000,function(){});
						});
				});
			');
			
			$admin_toolbar += '<button name="-Nothing" value="Toggle Hidden" id="togglehidden">Toggle Hidden</button>';
			$admin_toolbar += '<button name="-Nothing" value="Toggle Deleted" id="toggledeleted">Toggle Deleted</button>';
	case(((response_path)->endswith('/Reset/')));
			If: (Variable_Defined: 'rewAction');
					Session_End: -Name=(Var: ($rewAction + '_SessionName'));
					Cookie_Set:
						(Var: ($rewAction + '_SessionName'))='kilt off',
						-Domain=(Server_Name),
						-Expires=-9000,
						-Path='/',
						;
					Session_End: -Name=(Var: ($rewAction + '_SessionName'));
					if: action_param: 'exit';
							Redirect_URL: Action_Param('exit');
					else;
							Redirect_URL: (Var: ($rewAction + '_pathTo'));
					/if;
			Else;
					 Var: 'new_exit' = (Response_Path);
					$new_exit->(RemoveTrailing: $thisLevel_Name + '/');
					Redirect_URL: '../';
			/If;
	case($show_admin_content && ((response_path)->endswith('/Reset/')));
			If: (Variable_Defined: 'rewAction');
					Session_End: -Name=(Var: ($rewAction + '_SessionName'));
					Cookie_Set:
						(Var: ($rewAction + '_SessionName'))='kilt off',
						-Domain=(Server_Name),
						-Expires=-9000,
						-Path='/',
						;
					Session_End: -Name=(Var: ($rewAction + '_SessionName'));
					if: action_param: 'exit';
							Redirect_URL: Action_Param('exit');
					else;
							Redirect_URL: (Var: ($rewAction + '_pathTo'));
							//redirect_url('../');
					/if;
			Else;
					Var: 'new_exit' = (Response_Path);
					$new_exit->(RemoveTrailing: $thisLevel_Name + '/');
					Redirect_URL: '../';
			/If;
	case((response_path)->beginswith('/Admin/'$this_Listerator'/') && (response_path)->endswith('/Search/'));
			$page_title = $these;
			if(file_exists('/_Site/Listerators/'$this_Listerator'/admin-search.lasso'));
					// app-specific search
					include('/_Site/Listerators/'$this_Listerator'/admin-search.lasso');
			else(file_exists('/_Site/Listerators/admin-search.lasso'));
					// site-specific search
					include('/_Site/Listerators/admin-search.lasso');
			else;
					//the default Makerator search
					include('/_Makerator/Listerators/admin-search.lasso');
			/if;
	case(($show_admin_content && ((response_path)->contains('/Create/'))) || ($show_admin_content && ((response_path)->contains('/Edit/'))));
			
			if((response_path)->beginswith('/Admin/'$this_Listerator'/') && (response_path)->endswith('/Create/'));
						$REW_Action = $REW_Create;
							
			
						$public_content += '<div class="listerator-toolbar">
								<a class="button" href="' $REW_Base + '">View all '$these'</a>
								
								</div>';
							$public_content += @include('/_Makerator/_Library/form_generator.lasso');
					
			else((response_path)->beginswith('/Admin/'$this_Listerator'/') && string(response_path)->contains('/Edit/') && string(response_path)->contains('/Do/'));
						$REW_Action = $REW_Edit;
						$public_content += library('/_Makerator/_Library/form_processor.lasso');
						
						var('for_update'=array);

						iterate: (var($rewAction + '_Tables')), var('this_tableName');
								iterate((var: ($this_tableName->first '_params')), var('a_pair'));
										$public_content += '<p>a_pair: '$a_pair'</p>';
										var('this_column' = $a_pair->first);
										var('this_value' = $a_pair->second);
										
										iterate((var($rewAction + '_Fields')), var('a_map'));
												if($a_map->find('Field') == $this_column);
														var('this_type' = $a_map->find('type'));
														$public_content += '<p>' $this_type '</p>';
														$public_content += '<p>'$this_value->type'</p>';
														
														select($this_type);
															case('Set');
																$this_value->removeleading('set_');
															case('Datetime');
																$this_value = date($this_value)->format('%Q %T');
															case('Date');
																$this_value = date($this_value)->format('%Q');
														/select;
														$for_update->insert($this_column=$this_value);
												/if;
										/iterate;
										$public_content += '<hr>';
								/iterate;
						/iterate;


						
						
						$public_content += '<hr>';
						
						iterate($for_update, var('a_pair'));
								$public_content += '<p>a_pair: '$a_pair'</p>';
						/iterate;
						
						//$public_content += $theseParams;
						
						
						
						//$for_update->insert((var($rewAction + '_UIDfieldName'))=var(var($rewAction + '_UIDfieldName')));
						inline(
							$connection_db,
							-update,
							-table=var($rewAction + '_Table'),
							-keyfield=(var($rewAction + '_UIDfieldName')),
							-keyvalue=var(var($rewAction + '_UIDfieldName')),
							$for_update,
							);
								//$public_content += '<p><textarea>'action_statement'</textarea></p>';
								if: error_msg == 'No Error';
										//$public_content += '<textarea>'action_Statement'</textarea>';
										
										Session_End: -Name=(Var: ($rewAction + '_SessionName'));
										redirect_url: $REW_base'#saved';
								else;
										$page_title = 'Ooops!';
										$public_content += '<div class="warning">'error_msg'</div>';
										$public_content += '<p>'+action_statement+'</p>';
								/if;
						
						/inline;
			else((response_path)->beginswith('/Admin/'$this_Listerator'/') && string(response_path)->contains('/Edit/'));
					var('sql' = string);
					$REW_Action = $REW_Edit;
					$public_content += '<div class="listerator-toolbar">
							<a class="button" href="' $REW_Base + '/' $thisLevel_Name '">View this '$this'</a>
							<a class="button" href="' $REW_Base + 'Create/">Create new '$this'</a>
							<a class="button" href="' $REW_Base + '">View all '$these'</a>
							
							</div>';
					
					
					$sql = 'SELECT UID, ' (var($rewAction + '_Title_Field_Name')) ' FROM ' (var($rewAction + '_Table')) ' WHERE ' (var($rewAction + '_Table')) '.Keyword_URL = "' + $thisLevel_Name + '"';
					inline($connection_db, action_params, -sql=$sql);
							if(found_count == 0);
									$sql = 'SELECT UID, ' (var($rewAction + '_Title_Field_Name')) ' FROM ' (var($rewAction + '_Table')) ' WHERE ' (var($rewAction + '_Table')) '.UID = "' + $thisLevel_Name + '"';
									inline($connection_db, action_params, -sql=$sql);
											if(error_msg != 'No Error');
													$public_content += '<div class="warning">'error_msg'</div>';
													$public_content += '<textarea>'action_statement'</textarea>';
											else;
													rows;
															$page_title = column((var($rewAction + '_Title_Field_Name')));
															var(var($rewAction + '_UIDfieldName')=column('UID'));
													/rows;
											/if;
									/inline;
							else;
									rows;
											$page_title = column((var($rewAction + '_Title_Field_Name')));
											var(var($rewAction + '_UIDfieldName')=column('UID'));
									/rows;
							/if;
					/inline;
					define: -name=(var($rewAction + '_UIDfieldName')), -default=action_param('and');
					//$public_content += var(var($rewAction + '_UIDfieldName'));
					
					inline($connection_db, -sql='SELECT * FROM '(var($rewAction + '_Table'))' WHERE ' (var($rewAction + '_UIDfieldName')) ' = "' var(var($rewAction + '_UIDfieldName')) '"');
							//$public_content += found_count;
								rows;
										Loop: (Field_Name: -Count);
												var(field_Name(loop_Count)=Field(Field_Name(Loop_Count)));
										/Loop;
										$form_fields->insert($this_group);
										$public_content += @include('/_Makerator/_Library/form_generator.lasso');
								/rows;
					/inline;
					
			
			
			else((response_path)->beginswith('/Admin/'$this_Listerator'/') && (response_path)->endswith('/Create/Done/'));
			
			else((response_path)->beginswith('/Admin/'$this_Listerator'/') && (response_path)->endswith('/Create/Do/'));
						
						$public_content += library('/_Makerator/_Library/form_processor.lasso');
						
						var('for_insert'=array);


						iterate((var($rewAction + '_Tables')), var('a_table'));
								iterate(var($a_table->first '_params'), var('a_pair'));
										//$public_content += '<p>a_pair: '$a_pair'</p>';
										var('this_column' = $a_pair->first);
										var('this_value' = $a_pair->second);
										
										iterate((var($rewAction + '_Fields')), var('a_map'));
												if($a_map->find('Field') == $this_column);
														var('this_type' = $a_map->find('type'));
														//$public_content += '<p>' $this_type '</p>';
														//$public_content += '<p>'$this_value->type'</p>';
														
														select($this_type);
															case('Set');
																$this_value->removeleading('set_');
															case('Datetime');
																$this_value = date($this_value)->format('%Q %T');
															case('Date');
																$this_value = date($this_value)->format('%Q');
														/select;
														$for_insert->insert($this_column=$this_value);
												/if;
										/iterate;
										//$public_content += '<hr>';
								/iterate;
						/iterate;
						
						
						//$public_content += '<hr>';
						
						iterate($for_insert, var('a_pair'));
								$public_content += '<p>a_pair: '$a_pair'</p>';
								
								
								// grab keyword URL in case this is listerator admin
								$a_pair->first == 'Keyword_URL' && $this_Listerator == 'Listerators' ? var('new_Keyword_URL' = $a_pair->second);
								$a_pair->first == 'Title_Field_Name' && $this_Listerator == 'Listerators' ? var('new_Title_Field_Name' = $a_pair->second);
								$a_pair->first == 'Table_Name' && $this_Listerator == 'Listerators' ? var('new_Table_Name' = $a_pair->second);
								$a_pair->first == 'Display_Status_Defaults' && $this_Listerator == 'Listerators' ? var('new_Display_Status_Defaults' = ($a_pair->second));
						/iterate;
						
						$public_content += $for_insert;
						
						
						
						var('new_'var($rewAction + '_Table')'_UID') = lasso_uniqueid;
						$for_insert->insert('UID'=var('new_'var($rewAction + '_Table')'_UID'));
						inline(
							$connection_db,
							-add,
							-table=var($rewAction + '_Table'),
							$for_insert,
							);
								if: error_msg == 'No Error';
								


										/* 
											experimenting with tweets on updates -- if this goes anwhere it will not go in the default install
										*/
										/*
										//update twitter feed
										var('t') = twitter(
											-username='makerator',
											-password='m0mm135'
										);
										$t->update('A new ' $this ' has been posted at http://'server_name'/' $these '/' $keyword_url '/');
										*/
										
										
										if($this_Listerator == 'Listerators');
												// for Listerator creation and destorying, we need to do some stuff
												// first off: when creating a Listerator, we will create not only the 
												// table in question but also the directory in /_Site/Listerators
												
												// when we destroy a Listerator, however, we only kill off the 
												// directory IF IT IS EMPTY
												
												// we do NOT want Makerator deleting custom code, under any circumstance.
												
												// this means that when we create a listerator, of course, we must also 
												// CHECK TO SEE if the directory already exists.
												
												// let's do that now:
												//*
												if(file_exists('/_Site/Listerators/' $new_Keyword_URL '/'));
														$public_content += '<p class="">Directory exists</p>';
												else;
														$public_content += '<p class="">Directory does not exist</p>';
														file_create('/_Site/Listerators/' $new_Keyword_URL '/');
														inline($connection_files);
																file_CurrentError != 'No Error' ? $public_content += '<p class="">' File_CurrentError '</p>';
																file_CurrentError != 'No Error' ? Error_SetErrorMessage = 'Directory was unable to be created';
														/inline;
												/if;
												
												if(error_msg == 'No Error');
														inline(-sql='show tables WHERE Tables_in_Makerator = "' $new_Table_Name '"');
																$public_content += '<p class="">found:' found_count'</p>';
																$public_content += '<p class="">error:' error_msg'</p>';
																rows;
																		$public_content += '<p class="">'loop_count ': ' field('Tables_in_Makerator') '</p>';
																/rows;
														/inline;
														//*/
														
														// we also need to do a similar thing with tables
														var('table_exists'=false);
														
														//*
														inline(-sql='show tables WHERE Tables_in_Makerator = "' $new_Table_Name '"');
																$public_content += error_msg;
																rows;
																		field('Tables_in_Makerator');
																/rows;
																if(found_Count);
																		$public_content += '<p class="">Table exists</p>';
																		$table_exists = true;
																else;
																		$public_content += '<p class="">Table does not exist</p>';
																		
																/if;
														/inline;
														//*/
														
														// create the table!
														//*
														var('create_statement' = string);
														$create_statement += '


														CREATE TABLE `' $new_Table_Name '` (
														  `' $new_Title_Field_Name '` varchar(255) NOT NULL default \'\',
														  `Description` text,
														  `Date` datetime NOT NULL default \'0000-00-00 00:00:00\',
														  `Keyword_URL` varchar(255) NOT NULL default \'Must Be Unique\',
														  `Display_Status` set(' ($new_Display_Status_Defaults)') NOT NULL default ' $new_Display_Status_Defaults->split(',')->get(1) ',
														  `UID` varchar(28) NOT NULL default \'\',
														  PRIMARY KEY  (`UID`),
														  UNIQUE KEY `Keyword_URL` (`Keyword_URL`)
														) ENGINE=MyISAM DEFAULT CHARSET=utf8
														';
														$public_content += '<pre>'$create_statement'</pre>';
														
														inline($connection_db, -sql=$create_statement);
																if(error_msg != 'No Error');
																		$public_content += '<p class="">'error_msg'</p>';
																		$err = error_msg;
																/if;
														/inline;
														//*/
												else;
														$public_content += error_msg;
												/if;

										/if;
										if($err == 'Creation Error');
										else;
										//*
												Session_End: -Name=(Var: ($rewAction + '_SessionName'));
												redirect_url: $REW_base '#added';
										//*/
										/if;
										
								else;
										$page_title = 'Ooops!';
										if(error_msg >> 'Duplicate' && error_msg >> 'Key 2');
												$public_content = '<p>You have attempted to add an item with a URL that is identical to a URL already in the system (&ldquo;' $Keyword_URL '&rdquo;). </p>';
												$public_content += '<h3>What to do?</h3>';
												$public_content += '<p>Simply go back 1 page, edit the &ldquo;Keyword URL&rdquo; field to be something other than <strong>&ldquo;' $Keyword_URL'&rdquo;</strong>, then re-submit.</p>';
										else;
												$public_content += '<p class="">'error_msg'</p>';
										/if;
								/if;
						
						/inline;
			/if;
	case;
			//might be a specific '$this_Listerator' item
			var('sql' = string);
			var('thisKeyword_URL' = 'none');
			
			$sql = 'SELECT * FROM ' (var($rewAction + '_Table')) ' WHERE ' (var($rewAction + '_Table')) '.Keyword_URL = "' + $thisLevel_Name + '"';
			inline($connection_db, action_params, -sql=$sql, -inlinename=('show'+$this));
					if(found_count == 0);
							$sql = 'SELECT * FROM ' (var($rewAction + '_Table')) ' WHERE ' (var($rewAction + '_Table')) '.UID = "' + $thisLevel_Name + '"';
							inline($connection_db, action_params, -sql=$sql, -inlinename=('show'+$this));
									if(error_msg != 'No Error');
											$public_content += '<div class="warning">'error_msg'</div>';
											$public_content += '<textarea>'action_statement'</textarea>';
									else;
									/if;
							/inline;
					
					else(error_msg != 'No Error');
							$public_content += '<div class="warning">'error_msg'</div>';
							$public_content += '<textarea>'action_statement'</textarea>';
					else;
							//found_count;
							rows;
										$page_title = column('Title');
										
										var('thisUID' = column('UID'));
										var('thisKeyword_URL' = column('Keyword_URL'));
										//$thisKeyword_URL;
							/rows;
					/if;
			/inline;
			
			

			select(true);
				case((response_path)->endswith($thisKeyword_URL '/'));
				
						$public_content += '<div class="listerator-toolbar">
								<a class="button" href="' $REW_Base + 'Edit/' $thisLevel_Name '">Edit this '$this'</a>
								<a class="button" href="' $REW_Base + 'Create/">Create new '$this'</a>
								<a class="button" href="' $REW_Base + '">View all '$these'</a>
								
								</div>';
						if(file_exists('/_Site/Listerators/'$this_Listerator'/admin-details.lasso'));
								// app-specific details
								$public_content += include('/_Site/Listerators/'$this_Listerator'/admin-details.lasso');
						else(file_exists('/_Site/Listerators/admin-details.lasso'));
								// site-specific details
								$public_content += include('/_Site/Listerators/admin-details.lasso');
						else;
								//the default Makerator details
								$public_content +=include('/_Makerator/Listerators/admin-details.lasso');
						/if;
				case((response_path)->endswith('Do_Upload/'));
						var('sql' = string);
						
						var('pathTo_parent' = var('pathTo_level_'+($levels_count-1)));
						var('parent_LevelName' = $pathto_Parent->split('/')->get($pathto_Parent->split('/')->size -1));
						$sql = 'SELECT * FROM ' (var($rewAction + '_Table')) ' WHERE ' (var($rewAction + '_Table')) '.Keyword_URL = "' + $parent_LevelName + '"';
						
						
						//$sql;
						inline($connection_db, action_params, -sql=$sql, -inlinename=('show'+$this));
								rows;
									var('sponsorUID' = column('UID'));
								/rows;
						/inline;
						
						
						
						
						if(file_exists('/_Site/Listerators/'$this_Listerator'/do_image_upload.lasso'));
								// app-specific 
								$public_content += include('/_Site/Listerators/'$this_Listerator'/do_image_upload.lasso');
						else(file_exists('/_Site/Listerators/do_image_upload.lasso'));
								// site-specific
								$public_content += include('/_Site/Listerators/do_image_upload.lasso');
						else;
								//the default 
								$public_content +=include('/_Makerator/Listerators/do_image_upload.lasso');
						/if;
			/select;

	/select;
	$admin_toolbar += include('/_Makerator/_Library/app_create_link.lasso');
	$admin_toolbar += include('/_Makerator/_Library/app_listing_link.lasso');
]
